﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FrmMain;

namespace FMain
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        public int loginId;
        Dao dao = new Dao();
        private void Form3_Load(object sender, EventArgs e)
        {
            string loginName =Convert.ToString( dao.DoScalar(string.Format(@"select Uname from [User] where UId in ('{0}') ", loginId)));
            this.textBox1.Text = loginName;
            DataTable table = dao.GetTable("select * from food ");
            this.comboBox1.DataSource = table;
            this.comboBox1.DisplayMember = "FName";
            this.comboBox1.ValueMember = "Fid";
            //this.comboBox1.SelectedIndex = 0;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.Equals(string.Empty) || textBox3.Text.Equals(string.Empty))
            {
                MessageBox.Show("请填写完整数据");
            }
            else {
                double price = Convert.ToDouble(dao.DoScalar("select Fprice from food where fId = " + comboBox1.SelectedValue));
                if (dao.DoNonquery(string.Format(@"insert into a values({0},{1},{2},'{3}','{4}','{5}',0)", loginId, comboBox1.SelectedValue, textBox2.Text, dateTimePicker1.Text, textBox3.Text, price * Convert.ToInt32(this.textBox2.Text))) > 0)
                {
                    MessageBox.Show("订餐成功");
                    this.Close();
                    
                }
                else {
                    MessageBox.Show("订餐失败");
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
